package com.suarte.core;

import java.util.ArrayList;
import org.appfuse.model.BaseObject;

import javax.persistence.*;
import java.util.Date;
import java.util.List;
import org.appfuse.model.User;

/**
 * Created by IntelliJ IDEA.
 * User: Gcastillo
 * Date: Dec 30, 2010
 * Time: 4:21:50 PM
 * To change this template use File | Settings | File Templates.
 */
@Entity
@Table(name = "sa_remissions")
public class Remission extends BaseObject {

    private Long id;
    private Date date;
    private WorkOrder workOrder;
    private Employee employee;
    private String description;
    private String notes;
    private List<RemissionDetail> details = new ArrayList();
    private User createdBy;
    private Date createdOn = new Date();
    private User modifiedBy;
    private Date modifiedOn = new Date();
    private Long oldId;

    public Remission() {
    }

    @Id @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="REMISSION_SEQ")
    @SequenceGenerator(name="REMISSION_SEQ", sequenceName="REMISSION_SEQ",allocationSize=1)
    public Long getId() {
        return id;
    }

    @Column(name = "remission_date")
    @Temporal(javax.persistence.TemporalType.DATE)
    public Date getDate() {
        return date;
    }

    @ManyToOne
    @JoinColumn(name = "work_order_id")
    public WorkOrder getWorkOrder() {
        return workOrder;
    }

    @ManyToOne
    @JoinColumn(name = "employee_id")
    public Employee getEmployee() {
        return employee;
    }

    @Column(name = "description")
    public String getDescription() {
        return description;
    }

    @Column(name = "notes")
    public String getNotes() {
        return notes;
    }

    @OneToMany(mappedBy = "remission", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    public List<RemissionDetail> getDetails() {
        return details;
    }

    @ManyToOne
    @JoinColumn(name = "created_by")
    public User getCreatedBy() {
        return createdBy;
    }

    @ManyToOne
    @JoinColumn(name = "modified_by")
    public User getModifiedBy() {
        return modifiedBy;
    }

    @Column(name = "created_on")
    @Temporal(javax.persistence.TemporalType.DATE)
    public Date getCreatedOn() {
        return createdOn;
    }

    @Column(name = "modified_on")
    @Temporal(javax.persistence.TemporalType.DATE)
    public Date getModifiedOn() {
        return modifiedOn;
    }

    @Column(name = "old_id")
    public Long getOldId() {
        return oldId;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public void setWorkOrder(WorkOrder workOrder) {
        this.workOrder = workOrder;
    }

    public void setEmployee(Employee employee) {
        this.employee = employee;
    }

    public void setNotes(String notes) {
        this.notes = notes;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public void setDetails(List<RemissionDetail> details) {
        this.details = details;
    }

    public void setCreatedBy(User createdBy) {
        this.createdBy = createdBy;
    }

    public void setCreatedOn(Date createdOn) {
        this.createdOn = createdOn;
    }

    public void setModifiedBy(User modifiedBy) {
        this.modifiedBy = modifiedBy;
    }

    public void setModifiedOn(Date modifiedOn) {
        this.modifiedOn = modifiedOn;
    }

    public void setOldId(Long oldId) {
        this.oldId = oldId;
    }

    @Override
    public String toString() {
        return description;
    }

    @Override
    public boolean equals(Object other) {
        if (other == this) {
            return true;
        }
        if (!(other instanceof Remission)) {
            return false;
        }
        Remission _i = (Remission) other;
        return id.equals(_i.id);
    }

    @Override
    public int hashCode() {
        return id.hashCode();
    }

    public void addDetail(RemissionDetail detail) {
        detail.setRemission(this);
        details.add(detail);
    }
}
